# -*- coding: utf-8 -*-

"""
@Author  : James.xiaoli
@Time    : 2025/4/17 13:38
@File    : upload.py
模块注释：传输文件到服务器
    

"""

from PyQt5.QtCore import QThread, pyqtSignal

from helper import kodo_upload


class Upload(QThread):
    progress_signal = pyqtSignal(int) # 进度信号（0-100）
    finished = pyqtSignal(tuple)  # 完成信号

    def __init__(self, remote_file, local_file):
        super().__init__()
        self.ret = None
        self.remote_file = remote_file
        self.local_file = local_file



    def update_progress(self, uploaded, total):
        """更新上传进度"""
        if uploaded > total:
            uploaded = total
        progress = (uploaded / total) * 100
        self.progress_signal.emit(int(progress))


    def get_ret(self):
        return self.ret



    def run(self):
        ret =  kodo_upload(self.remote_file, self.local_file, self.update_progress)
        self.finished.emit(ret)


